package com.zt.chatgpt.config.ChatGPTSDK;

import com.zt.chatgpt.session.OpenAiSession;
import com.zt.chatgpt.session.OpenAiSessionFactory;
import com.zt.chatgpt.session.defaults.DefaultOpenAiSessionFactory;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author: zt
 * @Description: OpenAiSession 工厂配置开启
 * @create: 2024-05-17 21:28
 */

@Configuration
@EnableConfigurationProperties(ChatGPTSDKConfigProperties.class)
public class ChatGPTSDKConfig {

    @Bean(name = "chatGPTOpenAiSession")
    public OpenAiSession openAiSession(ChatGPTSDKConfigProperties  properties) {
        // 1. 配置信息写入
        com.zt.chatgpt.session.Configuration configuration = com.zt.chatgpt.session.Configuration.builder()
                .apiKey(properties.getApiSecretKey())
                .apiHost(properties.getApiHost())
                .build();

        // 2. 开始会话工厂
        OpenAiSessionFactory openAiSessionFactory = new DefaultOpenAiSessionFactory(configuration);

        // 3. 开启会话
        return openAiSessionFactory.openSession();
    }

}
